#include "std_c.h"
#include "i2c.h"
#include "srf10.h"
#include "raspi.h"
#include <linux/i2c-dev.h>
#include "std_c.h"
#include "stdio.h"


//---------------------------------------------------------------------------------------
// SRF10 Daten ueber I2C lesen
//
//---------------------------------------------------------------------------------------
unsigned int srf10daten (int portexaddress)
{
unsigned char buf[10];

I2C_Setup(I2C_SLAVE, portexaddress);
if(I2cError)
{
	I2C_PrintError();
	exit(1);
}
I2C_Write2(0x01,0x03);
I2C_Write2(0x02,0x80);
I2C_Write2(0x00,0x51);            // Register 0, Ausgabe Distanz in mm
usleep(650000);                   // Wartezeit bis Distanzermittlung abgeschlossen ca. 65us
I2C_Write1(0x00);               // Send Register to send from
I2C_Read(buf,4);

unsigned char highByte = buf[2];
unsigned char lowByte = buf[3];
unsigned int result = (highByte <<8) + lowByte; // Calculate range as a word value
printf("Software v: %u \n",buf[0]);
printf("Range was: %u\n",result);
return(result);

}
